﻿using EmbeddedSensorCloud.HTTP;
using System.Net;

namespace EmbeddedSensorCloud.Plugin.MicroERP
{
    public class Program : IPlugin
    {
        #region Fields

        private Controller _Controller;

        #endregion

        #region Constructor/Init

        public Program()
        {
            this._Controller = new Controller(DBType.MySQL, "SERVER = localhost; DATABASE = SWE4; UID = root; PASSWORD = ", new SpirePdfService());
        }

        public void Initialize()
        { }

        #endregion

        #region IPlugin

        public bool IsResponseable(Request request)
        {
            return request.Url.StartsWith("/api", true, System.Globalization.CultureInfo.InvariantCulture);
        }

        public Response Respond(Request request)
        {
            if (IsResponseable(request))
            {
                return this._Controller.CreateResponse(request);
            }
            return new Response(HttpStatusCode.BadRequest);
        }

        #endregion
    }
}
